import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import { title } from '@/settings'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
        path: '/login',
        component: () =>
            import ('@/views/login/index'),
        hidden: true
    },

    {
        path: '/404',
        component: () =>
            import ('@/views/404'),
        hidden: true
    },

    {
        path: '/',
        component: Layout,
        redirect: '/dashboard',
        children: [{
            path: 'dashboard',
            name: 'Dashboard',
            component: () =>
                import ('@/views/dashboard/index'),
            meta: { title: 'Dashboard', icon: 'dashboard' }
        }]
    },

    //栏目管理
    {
        path: '/category',
        component: Layout,
        children: [{
            path: 'index',
            name: 'category',
            component: () =>
                import ('@/pages/category/index.vue'),
            meta: { title: '栏目管理', icon: 'icon_1' }
        }]
    },
    //产品管理
    {
        path: '/product',
        component: Layout,
        children: [{
            path: 'index',
            name: 'product',
            component: () =>
                import ('@/pages/product/index.vue'),
            meta: { title: '产品管理', icon: 'icon_2' }
        }]
    },
    // 账单管理
    {
        path: '/account',
        component: Layout,
        meta: { title: '账单管理', icon: 'icon_3' },
        children: [{
                path: 'Custome',
                name: 'Custome',
                component: () =>
                    import ('@/pages/account/Custome.vue'),
                meta: { title: '顾客账单' }
            },
            {
                path: 'Employee',
                name: 'Employee',
                component: () =>
                    import ('@/pages/account/Employee.vue'),
                meta: { title: '员工账单' }
            },
            {
                path: 'System',
                name: 'System',
                component: () =>
                    import ('@/pages/account/System.vue'),
                meta: { title: '系统账单' }
            }
        ]
    },
    // 订单管理
    {
        path: '/orderList',
        component: Layout,
        children: [{
            path: 'index',
            name: 'orderList',
            component: () =>
                import ('@/pages/orderList/index.vue'),
            meta: { title: '订单管理', icon: 'icon_4' }

        }]

    },
    // 审核大厅
    {
        path: '/check',
        component: Layout,
        meta: { title: '审核大厅', icon: 'icon_5' },
        children: [{
                path: 'infoComment',
                name: 'infoComment',
                component: () =>
                    import ('@/pages/check/infoComment.vue'),
                meta: { title: '资讯评论' }
            },
            {
                path: 'orderComment',
                name: 'orderComment',
                component: () =>
                    import ('@/pages/check/orderComment.vue'),
                meta: { title: '订单评论' }
            },
            {
                path: 'certification',
                name: 'certification',
                component: () =>
                    import ('@/pages/check/certification.vue'),
                meta: { title: '实名认证' }
            },
            {
                path: 'accountApply',
                name: 'accountApply',
                component: () =>
                    import ('@/pages/check/certification.vue'),
                meta: { title: '账户变更' }
            }
        ]
    },
    // 顾客管理
    {
        path: '/custome',
        component: Layout,
        children: [{
                path: 'list',
                name: 'list',
                component: () =>
                    import ('@/pages/custome/list.vue'),
                meta: { title: '顾客管理', icon: 'icon_6' }
            },
            {
                path: 'details',
                name: 'details',
                hidden: true,
                component: () =>
                    import ('@/pages/custome/details.vue'),
                meta: { title: '顾客详情' }
            }
        ]
    },
    // 员工管理
    {
        path: '/waiter',
        component: Layout,
        children: [{
                path: 'list',
                name: 'list',
                component: () =>
                    import ('@/pages/waiter/list.vue'),
                meta: { title: '员工管理', icon: 'icon_7' }
            },
            {
                path: 'details',
                name: 'details',
                hidden: true,
                component: () =>
                    import ('@/pages/waiter/details.vue'),
                meta: { title: '员工详情' }
            }
        ]
    },
    // 网站资讯
    {
        path: '/article',
        component: Layout,
        meta: { title: '网站资讯', icon: 'icon_8' },
        children: [{
                path: 'list',
                name: 'list',
                component: () =>
                    import ('@/pages/article/list.vue'),
                meta: { title: '资讯信息' }
            },
            {
                path: 'details',
                name: 'details',
                component: () =>
                    import ('@/pages/article/details.vue'),
                meta: { title: '资讯分类' }
            },
            {
                path: 'publish',
                name: 'publish',
                hidden: true,
                component: () =>
                    import ('@/pages/article/publish.vue'),
                meta: { title: '发布资讯页面' }
            }
        ]
    },
    // 角色权限
    {
        path: '/privilege',
        component: Layout,
        meta: { title: '角色权限', icon: 'icon_9' },
        children: [{
                path: 'privilege',
                name: 'privilege',
                component: () =>
                    import ('@/pages/plivilege/privilege.vue'),
                meta: { title: '权限管理' }
            },
            {
                path: 'role',
                name: 'role',
                component: () =>
                    import ('@/pages/plivilege/role.vue'),
                meta: { title: '角色管理' }
            },
            {
                path: 'user',
                name: 'user',
                component: () =>
                    import ('@/pages/plivilege/user.vue'),
                meta: { title: '用户管理' },
            },
            {
                path: 'details',
                name: 'details',
                hidden: true,
                component: () =>
                    import ('@/pages/plivilege/details.vue'),
                meta: { title: '用户管理' },
            }
        ]
    },
    // 系统配置
    {
        path: '/baseConfig',
        component: Layout,
        children: [{
            path: 'list',
            name: 'list',
            component: () =>
                import ('@/pages/baseConfig/list.vue'),
            meta: { title: '系统配置', icon: 'icon_10' }
        }]
    },
    // 日志管理
    {
        path: '/log',
        component: Layout,
        children: [{
            path: 'list',
            name: 'list',
            component: () =>
                import ('@/pages/log/list.vue'),
            meta: { title: '日志管理', icon: 'icon_11' }

        }]
    },
    // 轮播管理
    {
        path: '/carousel',
        component: Layout,
        children: [{
            path: 'list',
            name: 'list',
            component: () =>
                import ('@/pages/carousel/list.vue'),
            meta: { title: '轮播管理', icon: 'icon_12' }

        }]
    },
    // 个人信息
    {
        path: '/person',
        component: Layout,
        children: [{
            path: 'list',
            name: 'list',
            component: () =>
                import ('@/pages/person/list.vue'),
            meta: { title: '个人信息', icon: 'icon_13' }

        }]
    }

]

const createRouter = () => new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router